#include <graphics.h>
#include <conio.h>
#include <math.h>

#define high 480
#define width 640
#define PI 3.14159

void main()
{
	initgraph(width,high);

	int center_x,center_y;		//指针的中心坐标
	center_x=width/2;
	center_y=high/2;

	int secondlength;			//秒针的长度
	secondlength=width/5;

	int minutelength;			//分针的长度
	minutelength=width/6;

	int hourlength;			//时针的长度
	hourlength=width/7;

	int secondend_x,secondend_y;			//秒针末尾的坐标
	int minuteend_x,minuteend_y;			//分针末尾的坐标
	int hourend_x,hourend_y;			//时针末尾的坐标

	float secondangle=0;		//秒针对应转动角度
	float minuteangle=0;		//分针对应转动角度
	float hourangle=0;		//时针对应转动角度

	int r;						//定义时钟半径
	r=secondlength+20;

	SYSTEMTIME ti;			//定义变量存储系统时简
							//定义变量存储系统时简
							//定义变量存储系统时简


	//输出时钟边框
	circle(center_x,center_y,r+5);

	//输出我的时钟
	outtextxy(center_x-25,center_y+width/6,"我的时钟");

	//输出时刻
	outtextxy(center_x+r/2,center_y-r+20,"1");	//1
	outtextxy(center_x+r-25,center_y-r/2,"2");	//2
	outtextxy(center_x+r-10,center_y,"3");		//3
	outtextxy(center_x+r-32,center_y+r/2,"4");	//4
	outtextxy(center_x+r/2,center_y+r-35,"5");	//5
	outtextxy(center_x,center_y+r-15,"6");		//6
	outtextxy(center_x-r/2,center_y+r-35,"7");	//7
	outtextxy(center_x-r+25,center_y+r/2,"8");	//8
	outtextxy(center_x-r,center_y,"9");			//9
	outtextxy(center_x-r+20,center_y-r/2,"10");	//10
	outtextxy(center_x-r/2,center_y-r+20,"11");	//11
	outtextxy(center_x,center_y-r,"12");		//12


	BeginBatchDraw();
	while(1)
	{
		GetLocalTime(&ti);				//系统时间的设置
		secondangle=ti.wSecond*2*PI/60; //系统时间的设置
		minuteangle=ti.wMinute*2*PI/60; //系统时间的设置
		hourangle=ti.wHour*2*PI/12;		//系统时间的设置

		secondend_x=center_x+secondlength*sin(secondangle);
		secondend_y=center_y-secondlength*cos(secondangle);

		minuteend_x=center_x+minutelength*sin(minuteangle);
		minuteend_y=center_y-minutelength*cos(minuteangle);

		hourend_x=center_x+hourlength*sin(hourangle);
		hourend_y=center_y-hourlength*cos(hourangle);

		//画秒针
		setlinestyle(PS_SOLID,2);
		setcolor(WHITE);
		line(center_x,center_y,secondend_x,secondend_y);
		FlushBatchDraw();

		//画分针
		setlinestyle(PS_SOLID,2);
		setcolor(RED);
		line(center_x,center_y,minuteend_x,minuteend_y);
		FlushBatchDraw();

		//画时针
		setlinestyle(PS_SOLID,2);
		setcolor(BLUE);
		line(center_x,center_y,hourend_x,hourend_y);
		FlushBatchDraw();

		Sleep(50);
		
		//隐藏前面一帧的秒针
		setcolor(BLACK);
		line(center_x,center_y,secondend_x,secondend_y);
		
		//隐藏前面一帧的分针
		setcolor(BLACK);
		line(center_x,center_y,minuteend_x,minuteend_y);

		//隐藏前面一帧的时针
		setcolor(BLACK);
		line(center_x,center_y,hourend_x,hourend_y);

	}
	EndBatchDraw();
	getch();
	closegraph();
}
